package org.zzz.hepotaiya.beans;

import java.lang.reflect.Method;
import java.util.Map;

import org.zzz.hepotaiya.enums.ResultType;

/**
 * バッチ情報クラス
 * 
 */
public class BatchInfo implements BatchResult {

	String batchName;
	
	Object returnObject;
	
	ResultType resultType;

	/**
	 * Component名
	 */
	String componentName;

	int phase;

	int index;
	
	/**
	 * 異常処理時終了フラグ
	 */
	boolean isErrorStop;

	/**
	 * 
	 */
	Class targetClass;
	
	/**
	 * 
	 */
	Object targetObject;

	/**
	 * メソッド名
	 */
	Method targetMethod;

	/**
	 * 依存Map{Class_Method=正否}
	 */
	Map<String, Boolean> dependencies;
	
	public String getBatchName() {
		return batchName;
	}

	public void setBatchName(String batchName) {
		this.batchName = batchName;
	}

	public String getComponentName() {
		return componentName;
	}

	public void setComponentName(String componentName) {
		this.componentName = componentName;
	}

	public Map<String, Boolean> getDependencies() {
		return dependencies;
	}

	public void setDependencies(Map<String, Boolean> dependencies) {
		this.dependencies = dependencies;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public boolean isErrorStop() {
		return isErrorStop;
	}

	public void setErrorStop(boolean isErrorStop) {
		this.isErrorStop = isErrorStop;
	}

	public int getPhase() {
		return phase;
	}

	public void setPhase(int phase) {
		this.phase = phase;
	}

	public ResultType getResultType() {
		return resultType;
	}

	public void setResultType(ResultType resultType) {
		this.resultType = resultType;
	}

	public Object getReturnObject() {
		return returnObject;
	}

	public void setReturnObject(Object returnObject) {
		this.returnObject = returnObject;
	}

	public Class getTargetClass() {
		return targetClass;
	}

	public void setTargetClass(Class targetClass) {
		this.targetClass = targetClass;
	}

	public Method getTargetMethod() {
		return targetMethod;
	}

	public void setTargetMethod(Method targetMethod) {
		this.targetMethod = targetMethod;
	}

	public Object getTargetObject() {
		return targetObject;
	}

	public void setTargetObject(Object targetObject) {
		this.targetObject = targetObject;
	}

	public void dispatchResultType(Class returnType, Object returnObject) {
		if (null == returnObject) {
			// void return
			if (void.class == returnType) {
				this.resultType = ResultType.SUCCESS;
				return;
			}
			// object return & null
			this.resultType = ResultType.FAILURE;
			return;
		}
		// ResultType return
		if (returnObject.getClass() == ResultType.class) {
			this.resultType = (ResultType)returnObject;
			return;
		}
		// boolean return
		if (returnObject.getClass() == boolean.class || returnObject.getClass() == Boolean.class) {
			this.resultType = ((Boolean)returnObject).booleanValue() == true ? ResultType.SUCCESS : ResultType.FAILURE; 
			return;
		}
		this.resultType = ResultType.SUCCESS;
	}
}
